package io.github.i678.startertools;

import io.github.i678.namedutils.api.Staffchat;
import io.github.i678.namedutils.api.utils.ConfigurationUtils;
import io.github.i678.namedutils.api.utils.LogUtils;
import io.github.i678.startertools.commands.CommandStaffchat;

import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.ArrayList;
import java.util.List;

public class StarterTools extends JavaPlugin {

    /**
     * Main plugin enable code.
     */
    @Override
    public void onEnable() {
        if(Bukkit.getPluginManager().getPlugin("NamedUtils").getName() == null) {
            Bukkit.getPluginManager().disablePlugin(this);
            return;
        }
        // setup the configuration
        getConfig().options().copyDefaults(true);
        saveConfig();
        
        // runs the initializations
        initCommands();
        Staffchat.setEnabled(ConfigurationUtils.getBoolean("plugins.startertools.staffchat.enable"));

        LogUtils.info("Starter Tools > Plugin is now enabled!");
    }

    /**
     * Command initializer.
     */
    public void initCommands() {
        // initialize aliases
        List<String> staffchatAlias = new ArrayList<>();
        staffchatAlias.add("sc");
        
        // add all the main commands
        Bukkit.getPluginCommand("staffchat").setExecutor(new CommandStaffchat());
        
        // setup all the aliases
        Bukkit.getPluginCommand("staffchat").setAliases(staffchatAlias);
    }

    /**
     * Main plugin disable code.
     */
    @Override
    public void onDisable() {
        LogUtils.info("Starter Tools > Plugin is now disabled!");
    }

    /**
    * Internal feature for getting the plugin.
    * @return Plugin - The Bukkit plugin class.
    */    
    public static Plugin getPlugin() {
        return Bukkit.getPluginManager().getPlugin("StarterTools");
    }

}